package com.api.core.service.impl;

import com.api.common.enums.DataSourceType;
import com.api.core.domain.query.tracing.serialization.SerializationQuery;
import com.api.core.domain.vo.tracing.serialization.SerializationVo;
import com.api.core.domain.vo.tree.TreeVo;
import com.api.core.mapper.SerializationMapper;
import com.api.core.service.ISerializationService;
import com.api.framework.datasource.DynamicDataSourceContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SerializationServiceImpl implements ISerializationService {
    @Autowired
    SerializationMapper serializationMapper;
    @Override
    public List<Double> generates(TreeVo vo) {
        DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE.name());
        List<Double> dataList = serializationMapper.generates(vo.getSerializationTabName(),vo);
        DynamicDataSourceContextHolder.clearDataSourceType();
        return dataList;
    }

    @Override
    public List<SerializationQuery> scroe(SerializationVo vo) {
        DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE.name());
        vo.initTableName();
        List<SerializationQuery> dataList = serializationMapper.scroe(vo);
        DynamicDataSourceContextHolder.clearDataSourceType();
        return dataList;
    }
}
